<template>
  <div>
    <div>
      <h2 style="text-align: center">发布新课程</h2>
    </div>
    <!-- 发布新课程 -->
    <el-steps
      :active="3"
      align-center
      process-status="wait"
      style="margin-bottom: 30px"
    >
      <el-step title="填写课程基本信息"></el-step>
      <el-step title="创建课程大纲"></el-step>
      <el-step title="发布课程"></el-step>
    </el-steps>
    <div class="info">
      <img :src="coursePublishInfo.cover" :alt="coursePublishInfo.title" />
      <div class="content">
        <h2>{{ coursePublishInfo.title }}</h2>
        <p>共{{ coursePublishInfo.lessonNum }}课时</p>
        <p>
          所属分类：{{ coursePublishInfo.subjectParentTitle }} —
          {{ coursePublishInfo.subjectTitle }}
        </p>
        <p>课程讲师：{{ coursePublishInfo.teacherName }}</p>
        <p class="price">￥{{ coursePublishInfo.price }}</p>
      </div>
    </div>
    <div style="margin-left: 20px">
      <el-button type="primary" plain @click="$router.go(-1)"
        >返回修改</el-button
      >
      <el-button type="primary" @click="publish()">发布课程</el-button>
    </div>
  </div>
</template>

<script>
import courseApi from "@/api/course";
export default {
  data() {
    return {
      courseId: "",
      coursePublishInfo: {}, // 课程发布信息
    };
  },
  created() {
    this.init();
  },
  methods: {
    //   初始化课程发布信息
    init() {
      if (this.$route.params && this.$route.params.id) {
        // 根据课程d获取当前要更新的课程信息,绑定到页面中
        this.courseId = this.$route.params.id;
        // 根据课程id通过api获取发布信息
        courseApi.getPublishById(this.courseId).then((res) => {
          this.coursePublishInfo = res.data;
        });
      }
    },
    //   发布课程
    publish() {
      //   根据课程id调用api将当前课程状态修改为发布
      courseApi.publishCourse(this.courseId).then((res) => {
        // 提示成功信息
        this.$message({
          type: "success",
          message: "发布成功!",
        });
      // 发布完成后跳转至列表页面
      this.$router.push({path:'/course/list'})
      });
    },
  },
};
</script>

<style scoped>
.info {
  background: #f5f5f5;
  border: 1px dashed #d5d5d5;
  padding: 20px;
  margin: 20px;
  display: flex;
}
.info .content {
  margin-left: 20px;
}
.info .content p {
  line-height: 32px;
}
.info .content .price {
  font-size: 30px;
  color: #b9321c;
}
.info img {
  width: 580px;
  height: 290px;
}
</style>